package com.jsh.ex.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieHttpSessionStrategy;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;

/**
 * 配置spring-session
 * 设置session的有效时间是一天，默认是1800s
 * session使用redis存储，可以共享
 * maxInactiveIntervalInSeconds = 100, redisNamespace = "xxxx" 类似: spring:session:xxxx:sessions
 * Created by wukai on 2017/9/14.
 */
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 24 * 60 * 60)
public class SessionConfig {

    /**
     * session传递策略，通过header或者cookie
     * @return
     */
    @Bean
    public HttpSessionStrategy httpSessionStrategy(){
//        return new HeaderHttpSessionStrategy(); //header策略验证失败，每次session都不一样
        return new CookieHttpSessionStrategy();
    }
}
